/**
 * Created by m on 2019/1/9.
 */
$(function () {
    $("#toTc").click(function () {
        window.location.href="WarehouseTrackingList.html?loginName=" + _loginName + "&token=" + _token;
    });
    function getTable(strategyId) {
        // var _token ='Zo0hVZ6QH3BoyyrLCp1dJJDsj%2FqN710%2B5pwcSv%2F9FZmFGKnEvblzgw%3D%3D';
        var _timestamp = new Date().getTime();
        var _secret = hex_md5(ip + '/Back/Strategy/AllPosition1111?timestamp=' + _timestamp + salt);
        $.ajax({
            type:"POST",
            url: ip + '/Back/Strategy/AllPosition1111?timestamp=' + _timestamp + '&secret=' + _secret + '&token=' + _token,
            dataType:'json',
            headers: {
                "Content-Type": "application/json",
                "Accept": "application/json;charset=utf-8",
            },
            data: JSON.stringify({
                "strategyId": strategyId
            }),
            success:function (data) {
                console.log(data)
                if (data.code == 1){
                    $("#trackTable tbody tr").remove();
                    var nowValue1 = data.data.nowValue1;//(number, optional): 个股合计： 当前金额 ,
                    var nowValue2 = data.data.nowValue2; //(number, optional): 期权合计： 当前金额 ,
                    var nowValue3 = data.data.nowValue3;//(number, optional): 总合计： 当前金额 ,
                    var positionValue1 = data.data.positionValue1;//(number, optional): 个股合计： 初始金额 ,
                    var positionValue2 = data.data.positionValue2;//(number, optional): 期权合计： 初始金额 ,
                    var positionValue3 = data.data.positionValue3;//(number, optional): 总合计： 初始金额 ,
                    var profitValue1 = data.data.profitValue1;//(number, optional): 个股合计： 盈亏金额 ,
                    var profitValue2 = data.data.profitValue2;//(number, optional): 期权合计： 盈亏金额 ,
                    var profitValue3 = data.data.profitValue3;//(number, optional): 总合计： 盈亏金额 ,
                    // var strategy1111PositionModels1 = data.data.strategy1111PositionModels1;//(Array[Strategy1111PositionModel], optional): 个股列表 ,
                    // var strategy1111PositionModels2 = data.data.strategy1111PositionModels2;//(Array[Strategy1111PositionModel], optional): 期权列表

                    var count1 = data.data.strategy1111PositionModels1.length;
                    var number1 = count1;
                    var count2 = data.data.strategy1111PositionModels2.length;
                    var number2 = count2;
                    for (let i=0;i<count1;i++){
                        var count_1 = i + 1;
                        // console.log(data.data.strategy1111PositionModels1[i].gmtCreate)
                        var pointPriceStr_1 =data.data.strategy1111PositionModels1[i].pointPriceStr || '';//(string, optional): 目标价 ,
                        var gmtCreate_1 = data.data.strategy1111PositionModels1[i].gmtCreate || '';//(string, optional): 操作时间 ,
                        var gmtSellAll_1 = data.data.strategy1111PositionModels1[i].gmtSellAll || '';//(string, optional): 平仓日期 ,
                        var notStopReason_1 = data.data.strategy1111PositionModels1[i].notStopReason || '';//(string, optional): 未止损原因 ,
                        var nowPrice_1 = data.data.strategy1111PositionModels1[i].nowPrice || '';//(number, optional): 当前价格 ,
                        var nowValue_1 = data.data.strategy1111PositionModels1[i].nowValue || '';//(number, optional): 当前金额 ,
                        var positionPrice_1 = data.data.strategy1111PositionModels1[i].positionPrice || '';//(number, optional): 成本价 ,
                        var positionValue_1 = data.data.strategy1111PositionModels1[i].positionValue || '';//(number, optional): 初始金额 ,
                        var positionVolume_1 = data.data.strategy1111PositionModels1[i].positionVolume || '';//(integer, optional): 持仓股数 ,
                        var profitRate_1 = parseInt(data.data.strategy1111PositionModels1[i].profitRate * 10000) / 100 + '%' || '';//(number, optional): 盈亏幅度 ,
                        var profitValue_1 = data.data.strategy1111PositionModels1[i].profitValue || '';//(number, optional): 盈亏金额 ,
                        var stockId_1 = data.data.strategy1111PositionModels1[i].stockId || '';//(string, optional): 股票代码 ,
                        var stockTypeStr_1 = data.data.strategy1111PositionModels1[i].stockTypeStr || '';//(string, optional): 期权，个股 ,
                        var stopPrice_1 = data.data.strategy1111PositionModels1[i].stopPrice || '';//(number, optional): 止损价格 ,
                        var tradeDirectionName_1 = data.data.strategy1111PositionModels1[i].tradeDirectionName || '';//(string, optional): 交易方向多空 ,
                        var tradeReason_1 = data.data.strategy1111PositionModels1[i].tradeReason || '';//(string, optional): 买入理由
                        if(i == 0){
                            var tr1 = "<tr class='tr1' count_1="+count_1+"stockTypeStr_1="+stockTypeStr_1+"stockId_1="+stockId_1+"tradeDirectionName_1="+tradeDirectionName_1+"positionPrice_1="+positionPrice_1+"nowPrice_1="+nowPrice_1+"profitRate_1="+profitRate_1+"profitValue_1="+profitValue_1+"positionValue_1="+positionValue_1+"nowValue_1="+nowValue_1+"positionVolume_1="+positionVolume_1+"tradeReason_1="+tradeReason_1+"stopPrice_1="+stopPrice_1+"pointPriceStr_1="+pointPriceStr_1+"notStopReason_1="+notStopReason_1+"gmtCreate_1="+gmtCreate_1+"gmtSellAll_1="+gmtSellAll_1+">" +
                                "<td>"+count_1+"</td><td rowspan="+number1+">"+stockTypeStr_1+"</td><td>"+stockId_1+"</td><td>"+tradeDirectionName_1+"</td><td>"+positionPrice_1+"</td><td>"+nowPrice_1+"</td><td>"+profitRate_1+"</td><td>"+profitValue_1+"</td><td>"+positionValue_1+"</td><td>"+nowValue_1+"</td><td>"+positionVolume_1+"</td><td>"+tradeReason_1+"</td><td>"+stopPrice_1+"</td><td>"+pointPriceStr_1+"</td><td>"+notStopReason_1+"</td><td>"+getMyDate(gmtCreate_1)+"</td><td>"+gmtSellAll_1+"</td></tr>"
                            $("#trackTable tbody").append(tr1);
                        }else {
                            var tr1 = "<tr class='tr1' count_1="+count_1+"stockId_1="+stockId_1+"tradeDirectionName_1="+tradeDirectionName_1+"positionPrice_1="+positionPrice_1+"nowPrice_1="+nowPrice_1+"profitRate_1="+profitRate_1+"profitValue_1="+profitValue_1+"positionValue_1="+positionValue_1+"nowValue_1="+nowValue_1+"positionVolume_1="+positionVolume_1+"tradeReason_1="+tradeReason_1+"stopPrice_1="+stopPrice_1+"pointPriceStr_1="+pointPriceStr_1+"notStopReason_1="+notStopReason_1+"gmtCreate_1="+gmtCreate_1+"gmtSellAll_1="+gmtSellAll_1+">" +
                                "<td>"+count_1+"</td><td>"+stockId_1+"</td><td>"+tradeDirectionName_1+"</td><td>"+positionPrice_1+"</td><td>"+nowPrice_1+"</td><td>"+profitRate_1+"</td><td>"+profitValue_1+"</td><td>"+positionValue_1+"</td><td>"+nowValue_1+"</td><td>"+positionVolume_1+"</td><td>"+tradeReason_1+"</td><td>"+stopPrice_1+"</td><td>"+pointPriceStr_1+"</td><td>"+notStopReason_1+"</td><td>"+getMyDate(gmtCreate_1)+"</td><td>"+gmtSellAll_1+"</td></tr>"
                            $("#trackTable tbody").append(tr1);
                        }
                    }
                    var tr1_count = "<tr class='tr1_count'profitValue1="+profitValue1+"positionValue1="+positionValue1+"nowValue1="+nowValue1+"><td colspan='7'>合计：</td><td>"+profitValue1+"</td><td>"+positionValue1+"</td><td>"+nowValue1+"</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>"
                    $("#trackTable tbody").append(tr1_count);
                    for (let j = 0; j < count2; j++){
                        var count_2 = j + 1;
                        var pointPriceStr_2 =data.data.strategy1111PositionModels2[j].pointPriceStr || '';//(string, optional): 目标价 ,
                        var gmtCreate_2 = data.data.strategy1111PositionModels2[j].gmtCreate || '';//(string, optional): 操作时间 ,
                        var gmtSellAll_2 = data.data.strategy1111PositionModels2[j].gmtSellAll || '';//(string, optional): 平仓日期 ,
                        var notStopReason_2 = data.data.strategy1111PositionModels2[j].notStopReason || '';//(string, optional): 未止损原因 ,
                        var nowPrice_2 = data.data.strategy1111PositionModels2[j].nowPrice || '';//(number, optional): 当前价格 ,
                        var nowValue_2 = data.data.strategy1111PositionModels2[j].nowValue || '';//(number, optional): 当前金额 ,
                        var positionPrice_2 = data.data.strategy1111PositionModels2[j].positionPrice || '';//(number, optional): 成本价 ,
                        var positionValue_2 = data.data.strategy1111PositionModels2[j].positionValue || '';//(number, optional): 初始金额 ,
                        var positionVolume_2 = data.data.strategy1111PositionModels2[j].positionVolume || '';//(integer, optional): 持仓股数 ,
                        var profitRate_2 = parseInt(data.data.strategy1111PositionModels2[j].profitRate * 10000) / 100 + '%' || '';//(number, optional): 盈亏幅度 ,
                        var profitValue_2 = data.data.strategy1111PositionModels2[j].profitValue || '';//(number, optional): 盈亏金额 ,
                        var stockId_2 = data.data.strategy1111PositionModels2[j].stockId || '';//(string, optional): 股票代码 ,
                        var stockTypeStr_2 = data.data.strategy1111PositionModels2[j].stockTypeStr || '';//(string, optional): 期权，个股 ,
                        var stopPrice_2 = data.data.strategy1111PositionModels2[j].stopPrice || '';//(number, optional): 止损价格 ,
                        var tradeDirectionName_2 = data.data.strategy1111PositionModels2[j].tradeDirectionName || '';//(string, optional): 交易方向多空 ,
                        var tradeReason_2 = data.data.strategy1111PositionModels2[j].tradeReason || '';//(string, optional): 买入理由
                        if(j==0){
                            var tr2 = "<tr class='tr2' count_2="+count_2+"stockTypeStr_2="+stockTypeStr_2+"stockId_2="+stockId_2+"tradeDirectionName_2="+tradeDirectionName_2+"positionPrice_2="+positionPrice_2+"nowPrice_2="+nowPrice_2+"profitRate_2="+profitRate_2+"profitValue_2="+profitValue_2+"positionValue_2="+positionValue_2+"nowValue_2="+nowValue_2+"positionVolume_2="+positionVolume_2+"tradeReason_2="+tradeReason_2+"stopPrice_2="+stopPrice_2+"pointPriceStr_2="+pointPriceStr_2+"notStopReason_2="+notStopReason_2+"gmtCreate_2="+gmtCreate_2+"gmtSellAll_2="+gmtSellAll_2+">" +
                                "<td>"+count_2+"</td><td rowspan="+number2+">"+stockTypeStr_2+"</td><td>"+stockId_2+"</td><td>"+tradeDirectionName_2+"</td><td>"+positionPrice_2+"</td><td>"+nowPrice_2+"</td><td>"+profitRate_2+"</td><td>"+profitValue_2+"</td><td>"+nowValue_2+"</td><td>"+positionValue_2+"</td><td>"+positionVolume_2+"</td><td>"+tradeReason_2+"</td><td>"+stopPrice_2+"</td><td>"+pointPriceStr_2+"</td><td>"+notStopReason_2+"</td><td>"+getMyDate(gmtCreate_2)+"</td><td>"+gmtSellAll_2+"</td></tr>"
                            $("#trackTable tbody").append(tr2);
                        }else {
                            var tr2 = "<tr class='tr2' count_2="+count_2+"stockId_2="+stockId_2+"tradeDirectionName_2="+tradeDirectionName_2+"positionPrice_2="+positionPrice_2+"nowPrice_2="+nowPrice_2+"profitRate_2="+profitRate_2+"profitValue_2="+profitValue_2+"positionValue_2="+positionValue_2+"nowValue_2="+nowValue_2+"positionVolume_2="+positionVolume_2+"tradeReason_2="+tradeReason_2+"stopPrice_2="+stopPrice_2+"pointPriceStr_2="+pointPriceStr_2+"notStopReason_2="+notStopReason_2+"gmtCreate_2="+gmtCreate_2+"gmtSellAll_2="+gmtSellAll_2+">" +
                                "<td>"+count_2+"</td><td>"+stockId_2+"</td><td>"+tradeDirectionName_2+"</td><td>"+positionPrice_2+"</td><td>"+nowPrice_2+"</td><td>"+profitRate_2+"</td><td>"+profitValue_2+"</td><td>"+nowValue_2+"</td><td>"+positionValue_2+"</td><td>"+positionVolume_2+"</td><td>"+tradeReason_2+"</td><td>"+stopPrice_2+"</td><td>"+pointPriceStr_2+"</td><td>"+notStopReason_2+"</td><td>"+getMyDate(gmtCreate_2)+"</td><td>"+gmtSellAll_2+"</td></tr>"
                            $("#trackTable tbody").append(tr2);
                        }
                    }
                    var tr2_count = "<tr class='tr1_count'nowValue2="+nowValue2+"profitValue2="+profitValue2+"positionValue2="+positionValue2+"><td colspan='7'>合计：</td><td>"+profitValue2+"</td><td>"+positionValue2+"</td><td>"+nowValue2+"</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>"
                    $("#trackTable tbody").append(tr2_count);
                    var tr3_count = "<tr class='tr3_count'nowValue3="+nowValue3+"profitValue3="+profitValue3+"positionValue3="+positionValue3+"><td colspan='7'>总合计：</td><td>"+profitValue3+"</td><td>"+positionValue3+"</td><td>"+nowValue3+"</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>"
                    $("#trackTable tbody").append(tr3_count);

                    checkView()
                }
            },
            error: function () {
                alert('请求持仓跟踪列表失败');
            }

        })
    };
    getTable(1111)
    // //表头固定
    // var tableCont = document.querySelector('.track_list_table');
    // tableCont.addEventListener('scroll', scrollHandle);

    function checkView() {
        $(".checkboxDiv input:checkbox").change(function () {
            var val = $(this).val();
            var check = $(this).attr('checked');
            if(check){
                $(this).removeAttr("checked");
                $(".checkboxTr").each(function () {
                    $(this).find('td').eq(val).hide();
                    $(this).find('th').eq(val).hide();
                })

            }
            else {
                $(this).attr({"checked":"checked"});
                $(".checkboxTr").each(function () {
                    $(this).find('th').eq(val).show();
                    $(this).find('td').eq(val).show();
                })
            }
        })
    }
})
